home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Source Code / Visual Basic Source Code.iso / vbsource / sframe16 / calc.frm (.txt) next >
Encoding:
Visual Basic Form  |  1997-11-28  |  17.0 KB  |  539 lines

  1. VERSION 4.00
  2. Begin VB.Form CALC 
  3.    BackColor       =   &H000000FF&
  4.    BorderStyle     =   1  'Fixed Single
  5.    Caption         =   "Calculator"
  6.    ClientHeight    =   3975
  7.    ClientLeft      =   2580
  8.    ClientTop       =   1485
  9.    ClientWidth     =   3270
  10.    ClipControls    =   0   'False
  11.    ControlBox      =   0   'False
  12.    BeginProperty Font 
  13.       name            =   "System"
  14.       charset         =   1
  15.       weight          =   700
  16.       size            =   9.75
  17.       underline       =   0   'False
  18.       italic          =   0   'False
  19.       strikethrough   =   0   'False
  20.    EndProperty
  21.    Height          =   4380
  22.    Icon            =   "CALC.frx":0000
  23.    Left            =   2520
  24.    LinkMode        =   1  'Source
  25.    LinkTopic       =   "Form1"
  26.    MaxButton       =   0   'False
  27.    ScaleHeight     =   3975
  28.    ScaleWidth      =   3270
  29.    Top             =   1140
  30.    Width           =   3390
  31.    Begin VB.CommandButton Command1 
  32.       Caption         =   "E&xit"
  33.       BeginProperty Font 
  34.          name            =   "System"
  35.          charset         =   1
  36.          weight          =   700
  37.          size            =   9.75
  38.          underline       =   0   'False
  39.          italic          =   0   'False
  40.          strikethrough   =   0   'False
  41.       EndProperty
  42.       Height          =   495
  43.       Left            =   2280
  44.       TabIndex        =   20
  45.       Top             =   3360
  46.       Width           =   855
  47.    End
  48.    Begin VB.CommandButton Number 
  49.       Caption         =   "7"
  50.       BeginProperty Font 
  51.          name            =   "System"
  52.          charset         =   1
  53.          weight          =   700
  54.          size            =   9.75
  55.          underline       =   0   'False
  56.          italic          =   0   'False
  57.          strikethrough   =   0   'False
  58.       EndProperty
  59.       Height          =   480
  60.       Index           =   7
  61.       Left            =   120
  62.       TabIndex        =   7
  63.       Top             =   600
  64.       Width           =   480
  65.    End
  66.    Begin VB.CommandButton Number 
  67.       Caption         =   "8"
  68.       BeginProperty Font 
  69.          name            =   "System"
  70.          charset         =   1
  71.          weight          =   700
  72.          size            =   9.75
  73.          underline       =   0   'False
  74.          italic          =   0   'False
  75.          strikethrough   =   0   'False
  76.       EndProperty
  77.       Height          =   480
  78.       Index           =   8
  79.       Left            =   720
  80.       TabIndex        =   8
  81.       Top             =   600
  82.       Width           =   480
  83.    End
  84.    Begin VB.CommandButton Number 
  85.       Caption         =   "9"
  86.       BeginProperty Font 
  87.          name            =   "System"
  88.          charset         =   1
  89.          weight          =   700
  90.          size            =   9.75
  91.          underline       =   0   'False
  92.          italic          =   0   'False
  93.          strikethrough   =   0   'False
  94.       EndProperty
  95.       Height          =   480
  96.       Index           =   9
  97.       Left            =   1320
  98.       TabIndex        =   9
  99.       Top             =   600
  100.       Width           =   480
  101.    End
  102.    Begin VB.CommandButton Cancel 
  103.       Caption         =   "C"
  104.       BeginProperty Font 
  105.          name            =   "System"
  106.          charset         =   1
  107.          weight          =   700
  108.          size            =   9.75
  109.          underline       =   0   'False
  110.          italic          =   0   'False
  111.          strikethrough   =   0   'False
  112.       EndProperty
  113.       Height          =   480
  114.       Left            =   2040
  115.       TabIndex        =   10
  116.       Top             =   600
  117.       Width           =   480
  118.    End
  119.    Begin VB.CommandButton CancelEntry 
  120.       Caption         =   "CE"
  121.       BeginProperty Font 
  122.          name            =   "System"
  123.          charset         =   1
  124.          weight          =   700
  125.          size            =   9.75
  126.          underline       =   0   'False
  127.          italic          =   0   'False
  128.          strikethrough   =   0   'False
  129.       EndProperty
  130.       Height          =   480
  131.       Left            =   2640
  132.       TabIndex        =   11
  133.       Top             =   600
  134.       Width           =   480
  135.    End
  136.    Begin VB.CommandButton Number 
  137.       Caption         =   "4"
  138.       BeginProperty Font 
  139.          name            =   "System"
  140.          charset         =   1
  141.          weight          =   700
  142.          size            =   9.75
  143.          underline       =   0   'False
  144.          italic          =   0   'False
  145.          strikethrough   =   0   'False
  146.       EndProperty
  147.       Height          =   480
  148.       Index           =   4
  149.       Left            =   120
  150.       TabIndex        =   4
  151.       Top             =   1200
  152.       Width           =   480
  153.    End
  154.    Begin VB.CommandButton Number 
  155.       Caption         =   "5"
  156.       BeginProperty Font 
  157.          name            =   "System"
  158.          charset         =   1
  159.          weight          =   700
  160.          size            =   9.75
  161.          underline       =   0   'False
  162.          italic          =   0   'False
  163.          strikethrough   =   0   'False
  164.       EndProperty
  165.       Height          =   480
  166.       Index           =   5
  167.       Left            =   720
  168.       TabIndex        =   5
  169.       Top             =   1200
  170.       Width           =   480
  171.    End
  172.    Begin VB.CommandButton Number 
  173.       Caption         =   "6"
  174.       BeginProperty Font 
  175.          name            =   "System"
  176.          charset         =   1
  177.          weight          =   700
  178.          size            =   9.75
  179.          underline       =   0   'False
  180.          italic          =   0   'False
  181.          strikethrough   =   0   'False
  182.       EndProperty
  183.       Height          =   480
  184.       Index           =   6
  185.       Left            =   1320
  186.       TabIndex        =   6
  187.       Top             =   1200
  188.       Width           =   480
  189.    End
  190.    Begin VB.CommandButton Operator 
  191.       Caption         =   "+"
  192.       BeginProperty Font 
  193.          name            =   "System"
  194.          charset         =   1
  195.          weight          =   700
  196.          size            =   9.75
  197.          underline       =   0   'False
  198.          italic          =   0   'False
  199.          strikethrough   =   0   'False
  200.       EndProperty
  201.       Height          =   480
  202.       Index           =   1
  203.       Left            =   2040
  204.       TabIndex        =   12
  205.       Top             =   1200
  206.       Width           =   480
  207.    End
  208.    Begin VB.CommandButton Operator 
  209.       Caption         =   "-"
  210.       BeginProperty Font 
  211.          name            =   "System"
  212.          charset         =   1
  213.          weight          =   700
  214.          size            =   9.75
  215.          underline       =   0   'False
  216.          italic          =   0   'False
  217.          strikethrough   =   0   'False
  218.       EndProperty
  219.       Height          =   480
  220.       Index           =   3
  221.       Left            =   2640
  222.       TabIndex        =   13
  223.       Top             =   1200
  224.       Width           =   480
  225.    End
  226.    Begin VB.CommandButton Number 
  227.       Caption         =   "1"
  228.       BeginProperty Font 
  229.          name            =   "System"
  230.          charset         =   1
  231.          weight          =   700
  232.          size            =   9.75
  233.          underline       =   0   'False
  234.          italic          =   0   'False
  235.          strikethrough   =   0   'False
  236.       EndProperty
  237.       Height          =   480
  238.       Index           =   1
  239.       Left            =   120
  240.       TabIndex        =   1
  241.       Top             =   1800
  242.       Width           =   480
  243.    End
  244.    Begin VB.CommandButton Number 
  245.       Caption         =   "2"
  246.       BeginProperty Font 
  247.          name            =   "System"
  248.          charset         =   1
  249.          weight          =   700
  250.          size            =   9.75
  251.          underline       =   0   'False
  252.          italic          =   0   'False
  253.          strikethrough   =   0   'False
  254.       EndProperty
  255.       Height          =   480
  256.       Index           =   2
  257.       Left            =   720
  258.       TabIndex        =   2
  259.       Top             =   1800
  260.       Width           =   480
  261.    End
  262.    Begin VB.CommandButton Number 
  263.       Caption         =   "3"
  264.       BeginProperty Font 
  265.          name            =   "System"
  266.          charset         =   1
  267.          weight          =   700
  268.          size            =   9.75
  269.          underline       =   0   'False
  270.          italic          =   0   'False
  271.          strikethrough   =   0   'False
  272.       EndProperty
  273.       Height          =   480
  274.       Index           =   3
  275.       Left            =   1320
  276.       TabIndex        =   3
  277.       Top             =   1800
  278.       Width           =   480
  279.    End
  280.    Begin VB.CommandButton Operator 
  281.       Caption         =   "X"
  282.       BeginProperty Font 
  283.          name            =   "System"
  284.          charset         =   1
  285.          weight          =   700
  286.          size            =   9.75
  287.          underline       =   0   'False
  288.          italic          =   0   'False
  289.          strikethrough   =   0   'False
  290.       EndProperty
  291.       Height          =   480
  292.       Index           =   2
  293.       Left            =   2040
  294.       TabIndex        =   14
  295.       Top             =   1800
  296.       Width           =   480
  297.    End
  298.    Begin VB.CommandButton Operator 
  299.       Caption         =   "/"
  300.       BeginProperty Font 
  301.          name            =   "System"
  302.          charset         =   1
  303.          weight          =   700
  304.          size            =   9.75
  305.          underline       =   0   'False
  306.          italic          =   0   'False
  307.          strikethrough   =   0   'False
  308.       EndProperty
  309.       Height          =   480
  310.       Index           =   0
  311.       Left            =   2640
  312.       TabIndex        =   15
  313.       Top             =   1800
  314.       Width           =   480
  315.    End
  316.    Begin VB.CommandButton Number 
  317.       Caption         =   "0"
  318.       BeginProperty Font 
  319.          name            =   "System"
  320.          charset         =   1
  321.          weight          =   700
  322.          size            =   9.75
  323.          underline       =   0   'False
  324.          italic          =   0   'False
  325.          strikethrough   =   0   'False
  326.       EndProperty
  327.       Height          =   480
  328.       Index           =   0
  329.       Left            =   120
  330.       TabIndex        =   0
  331.       Top             =   2400
  332.       Width           =   1080
  333.    End
  334.    Begin VB.CommandButton Decimal 
  335.       Caption         =   "."
  336.       BeginProperty Font 
  337.          name            =   "System"
  338.          charset         =   1
  339.          weight          =   700
  340.          size            =   9.75
  341.          underline       =   0   'False
  342.          italic          =   0   'False
  343.          strikethrough   =   0   'False
  344.       EndProperty
  345.       Height          =   480
  346.       Left            =   1320
  347.       TabIndex        =   18
  348.       Top             =   2400
  349.       Width           =   480
  350.    End
  351.    Begin VB.CommandButton Operator 
  352.       Caption         =   "="
  353.       BeginProperty Font 
  354.          name            =   "System"
  355.          charset         =   1
  356.          weight          =   700
  357.          size            =   9.75
  358.          underline       =   0   'False
  359.          italic          =   0   'False
  360.          strikethrough   =   0   'False
  361.       EndProperty
  362.       Height          =   480
  363.       Index           =   4
  364.       Left            =   2040
  365.       TabIndex        =   16
  366.       Top             =   2400
  367.       Width           =   480
  368.    End
  369.    Begin VB.CommandButton Percent 
  370.       Caption         =   "%"
  371.       BeginProperty Font 
  372.          name            =   "System"
  373.          charset         =   1
  374.          weight          =   700
  375.          size            =   9.75
  376.          underline       =   0   'False
  377.          italic          =   0   'False
  378.          strikethrough   =   0   'False
  379.       EndProperty
  380.       Height          =   480
  381.       Left            =   2640
  382.       TabIndex        =   17
  383.       Top             =   2400
  384.       Width           =   480
  385.    End
  386.    Begin VB.Label Readout 
  387.       Alignment       =   1  'Right Justify
  388.       BackColor       =   &H00FFFFFF&
  389.       BorderStyle     =   1  'Fixed Single
  390.       Caption         =   "0."
  391.       BeginProperty Font 
  392.          name            =   "MS Sans Serif"
  393.          charset         =   1
  394.          weight          =   700
  395.          size            =   12
  396.          underline       =   0   'False
  397.          italic          =   0   'False
  398.          strikethrough   =   0   'False
  399.       EndProperty
  400.       ForeColor       =   &H00000000&
  401.       Height          =   375
  402.       Left            =   120
  403.       TabIndex        =   19
  404.       Top             =   105
  405.       Width           =   3000
  406.    End
  407. Attribute VB_Name = "CALC"
  408. Attribute VB_Creatable = False
  409. Attribute VB_Exposed = False
  410. ' ------------------------------------------------------------------------
  411. '               Copyright (C) 1994 Microsoft Corporation
  412. ' You have a royalty-free right to use, modify, reproduce and distribute
  413. ' the Sample Application Files (and/or any modified version) in any way
  414. ' you find useful, provided that you agree that Microsoft has no warranty,
  415. ' obligations or liability for any Sample Application Files.
  416. ' ------------------------------------------------------------------------
  417. Option Explicit
  418. Dim Op1, Op2                ' Previously input operand.
  419. Dim DecimalFlag As Integer  ' Decimal point present yet?
  420. Dim NumOps As Integer       ' Number of operands.
  421. Dim LastInput               ' Indicate type of last keypress event.
  422. Dim OpFlag                  ' Indicate pending operation.
  423. Dim TempReadout
  424. ' Click event procedure for C (cancel) key.
  425. ' Reset the display and initializes variables.
  426. Private Sub Cancel_Click()
  427.     ReadOut = Format(0, "0.")
  428.     Op1 = 0
  429.     Op2 = 0
  430.     Form_Load
  431. End Sub
  432. ' Click event procedure for CE (cancel entry) key.
  433. Private Sub CancelEntry_Click()
  434.     ReadOut = Format(0, "0.")
  435.     DecimalFlag = False
  436.     LastInput = "CE"
  437. End Sub
  438. Private Sub Command1_Click()
  439.     Unload Me
  440. End Sub
  441. ' Click event procedure for decimal point (.) key.
  442. ' If last keypress was an operator, initialize
  443. ' readout to "0." Otherwise, append a decimal
  444. ' point to the display.
  445. Private Sub Decimal_Click()
  446.     If LastInput = "NEG" Then
  447.         ReadOut = Format(0, "-0.")
  448.     ElseIf LastInput <> "NUMS" Then
  449.         ReadOut = Format(0, "0.")
  450.     End If
  451.     DecimalFlag = True
  452.     LastInput = "NUMS"
  453. End Sub
  454. ' Initialization routine for the form.
  455. ' Set all variables to initial values.
  456. Private Sub Form_Load()
  457.     DecimalFlag = False
  458.     NumOps = 0
  459.     LastInput = "NONE"
  460.     OpFlag = " "
  461.     ReadOut = Format(0, "0.")
  462.     Decimal.Caption = Format(0, ".")
  463. End Sub
  464. ' Click event procedure for number keys (0-9).
  465. ' Append new number to the number in the display.
  466. Private Sub Number_Click(Index As Integer)
  467.     If LastInput <> "NUMS" Then
  468.         ReadOut = Format(0, ".")
  469.         DecimalFlag = False
  470.     End If
  471.     If DecimalFlag Then
  472.         ReadOut = ReadOut + Number(Index).Caption
  473.     Else
  474.         ReadOut = Left(ReadOut, InStr(ReadOut, Format(0, ".")) - 1) + Number(Index).Caption + Format(0, ".")
  475.     End If
  476.     If LastInput = "NEG" Then ReadOut = "-" & ReadOut
  477.     LastInput = "NUMS"
  478. End Sub
  479. ' Click event procedure for operator keys (+, -, x, /, =).
  480. ' If the immediately preceeding keypress was part of a
  481. ' number, increments NumOps. If one operand is present,
  482. ' set Op1. If two are present, set Op1 equal to the
  483. ' result of the operation on Op1 and the current
  484. ' input string, and display the result.
  485. Private Sub Operator_Click(Index As Integer)
  486.     TempReadout = ReadOut
  487.     If LastInput = "NUMS" Then
  488.         NumOps = NumOps + 1
  489.     End If
  490.     Select Case NumOps
  491.         Case 0
  492.         If Operator(Index).Caption = "-" And LastInput <> "NEG" Then
  493.             ReadOut = "-" & ReadOut
  494.             LastInput = "NEG"
  495.         End If
  496.         Case 1
  497.         Op1 = ReadOut
  498.         If Operator(Index).Caption = "-" And LastInput <> "NUMS" And OpFlag <> "=" Then
  499.             ReadOut = "-"
  500.             LastInput = "NEG"
  501.         End If
  502.         Case 2
  503.         Op2 = TempReadout
  504.         Select Case OpFlag
  505.             Case "+"
  506.                 Op1 = CDbl(Op1) + CDbl(Op2)
  507.             Case "-"
  508.                 Op1 = CDbl(Op1) - CDbl(Op2)
  509.             Case "X"
  510.                 Op1 = CDbl(Op1) * CDbl(Op2)
  511.             Case "/"
  512.                 If Op2 = 0 Then
  513.                    MsgBox "Can't divide by zero", 48, "Calculator"
  514.                 Else
  515.                    Op1 = CDbl(Op1) / CDbl(Op2)
  516.                 End If
  517.             Case "="
  518.                 Op1 = CDbl(Op2)
  519.             Case "%"
  520.                 Op1 = CDbl(Op1) * CDbl(Op2)
  521.             End Select
  522.         ReadOut = Op1
  523.         NumOps = 1
  524.     End Select
  525.     If LastInput <> "NEG" Then
  526.         LastInput = "OPS"
  527.         OpFlag = Operator(Index).Caption
  528.     End If
  529. End Sub
  530. ' Click event procedure for percent key (%).
  531. ' Compute and display a percentage of the first operand.
  532. Private Sub Percent_Click()
  533.     ReadOut = ReadOut / 100
  534.     LastInput = "Ops"
  535.     OpFlag = "%"
  536.     NumOps = NumOps + 1
  537.     DecimalFlag = True
  538. End Sub
  539.